import { nilV } from "utils";
import { GlobalNotification } from "./globalNotification";
import type { AppNotificationEnum } from "./globalNotification/eventSource/const";

// 注册
function registerNotification(notification: AppNotificationEnum, handler: (...args: any) => void) {
    let event = GlobalNotification[notification];
    if (nilV(event)) {
        return;
    }
    event.register(handler);
}
// 移除
function removeNotification(notification: AppNotificationEnum, handler?: (...args: any) => void) {
    let event = GlobalNotification[notification];
    if (nilV(event)) {
        return;
    }
    event.remove(handler);
}

// 触发通知
function emitNotification(notification: AppNotificationEnum, ...args: any) {
    let event = GlobalNotification[notification];
    if (nilV(event)) {
        return;
    }
    event.emits(...args);
}

export { registerNotification, removeNotification, emitNotification };
